home *** CD-ROM | disk | FTP | other *** search
/ Mac-Source 1994 July / Mac-Source_July_1994.iso / C and C++ / System / Incognito / cdev / CControlPanelMain.cp < prev    next >
Text File  |  1994-02-06  |  2KB  |  89 lines

  1. #ifndef __EVENTS__
  2. #include <Events.h>
  3. #endif
  4.  
  5. #ifndef __DIALOGS__
  6. #include <Dialogs.h>
  7. #endif
  8.  
  9. #ifndef __DEVICES__
  10. #include <Devices.h>
  11. #endif
  12.  
  13. #ifndef __OSUTILS__
  14. #include <OSUtils.h>
  15. #endif
  16.  
  17. #ifndef __CCONTROLPANEL__
  18. #include "CControlPanel.h"
  19. #endif
  20.  
  21. #ifdef __cplusplus
  22. extern "C" {
  23. #endif
  24.  
  25. pascal long EntryPoint(short message, short item, short numItems, short reserved, EventRecord *theEvent, long refCon, DialogPtr theDialog);
  26.  
  27. #ifdef __cplusplus
  28. }
  29. #endif
  30.  
  31. Boolean    CanPanelRun(void);
  32. long    CallControlPanel(short message, short item, EventRecord *theEvent, DialogPtr theDialog, long refCon);
  33.  
  34. pascal long EntryPoint(short message, short item, short numItems, short reserved, EventRecord *theEvent, long refCon, DialogPtr theDialog)
  35. {
  36.     switch (message)
  37.     {
  38.         case macDev:            // can this run? Return true if possible, false if not.
  39.             refCon = CanPanelRun();
  40.             break;
  41.         case initDev:
  42.         {
  43.             CControlPanel    *thePanel;
  44.             thePanel = new CControlPanel(numItems);
  45.             if (thePanel)
  46.             {
  47.                 refCon = (long) thePanel;
  48.                 refCon = CallControlPanel(message, item, theEvent, theDialog, refCon);
  49.             }
  50.             else refCon = cdevMemErr;
  51.             break;
  52.         }
  53.         default:
  54.             refCon = CallControlPanel(message, item, theEvent, theDialog, refCon);
  55.             break;
  56.     }
  57.     return refCon;
  58. }
  59.  
  60. long CallControlPanel(short message, short item, EventRecord *theEvent, DialogPtr theDialog, long refCon)
  61. {
  62.     CControlPanel *thePanel;
  63.     
  64.     if (refCon == cdevUnset) return cdevGenErr;
  65.     
  66.     thePanel = (CControlPanel *)refCon;
  67.     thePanel->SetArguments(item, theEvent, theDialog);
  68.     refCon = thePanel->DispatchMessage(message);
  69.     switch (refCon)
  70.     {
  71.         case cdevGenErr:
  72.         case cdevMemErr:
  73.         case cdevResErr:
  74.             delete thePanel;
  75.         default:
  76.             break;
  77.     }
  78.     return refCon;
  79. }
  80.  
  81. Boolean CanPanelRun(void)
  82. {
  83.     SysEnvRec    theWorld;
  84.     
  85.     SysEnvirons(curSysEnvVers, &theWorld);
  86.     
  87.     if (theWorld.systemVersion < 0x0700) return false;
  88.     return true;
  89. }